// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   WriteXml.java

package com.xml;

import include.excel_export.ReaderHelper;
import java.io.*;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.List;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;

public class WriteXml
{

	private ReaderHelper a;
	private String _fldfor;
	private SAXBuilder builder;
	private Document doc;
	private Element _flddo;
	private Element root;

	public WriteXml()
	{
		a = null;
		_fldfor = null;
		builder = null;
		doc = null;
		_flddo = null;
		root = null;
	}

	public WriteXml(String s)
	{
		a = null;
		_fldfor = null;
		builder = null;
		doc = null;
		_flddo = null;
		root = null;
		a(s);
	}

	private void a(String s)
	{
		try
		{
			_fldfor = s;
			builder = new SAXBuilder();
			doc = builder.build(new File(_fldfor));
			root = doc.getRootElement();
		}
		catch (Exception exception)
		{
			exception.printStackTrace();
		}
	}

	private void a()
	{
		try
		{
			Format format = Format.getCompactFormat();
			format.setEncoding("UTF-8");
			format.setIndent("  ");
			XMLOutputter XMLOut = new XMLOutputter(format);
			XMLOut.output(doc, new FileOutputStream(_fldfor));
		}
		catch (FileNotFoundException filenotfoundexception)
		{
			filenotfoundexception.printStackTrace();
		}
		catch (IOException ioexception)
		{
			ioexception.printStackTrace();
		}
	}

	public void setFile(String s)
	{
		a(s);
	}

	public void update(String ss, String ss1, ResultSet rs, String aa, String bb[])
		throws SQLException
	{
		root.removeChildren(ss);
		Element element = new Element(ss);
		element.setAttribute("nums", aa);
		root.addContent(element);
		for (int i = 0; rs.next(); i++)
		{
			Element element1 = new Element(ss1);
			element1.setAttribute("name", rs.getString("customer_name"));
			element1.setAttribute("color", bb[i]);
			element1.setAttribute("value", rs.getString("sale_price_sum"));
			element1.setAttribute("link", (new StringBuilder("http://localhost:8080/erp/crm/file/query.jsp?customer_ID=")).append(rs.getString("customer_ID")).toString());
			element.addContent(element1);
		}

		a();
	}

	public String getValue(String ss)
	{
		List list = root.getChildren(ss);
		Iterator loop = list.iterator();
		if (loop.hasNext())
		{
			Element element = (Element)loop.next();
			return element.getAttributeValue("value");
		} else
		{
			return null;
		}
	}

	public String getDynamic(String ss)
	{
		List list = root.getChildren(ss);
		Iterator loop = list.iterator();
		if (loop.hasNext())
		{
			Element element = (Element)loop.next();
			return element.getAttributeValue("dynamic");
		} else
		{
			return null;
		}
	}
}
